home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Personal Computer World 2009 February
/
PCWFEB09.iso
/
Software
/
Resources
/
Chat & Communication
/
Digsby build 37
/
digsby_setup.exe
/
lib
/
common
/
MultiImage.pyo
(
.txt
)
< prev
next >
Wrap
Python Compiled Bytecode
|
2008-10-13
|
7KB
|
243 lines
# Source Generated with Decompyle++
# File: in.pyo (Python 2.5)
from util import print_timing
from util import to_storage
import util
import syck
import wx
class MultiImage(object):
def __init__(self, image_list):
self.images = []
self.tags = { }
SplitImage2 = SplitImage2
import SplitImage2
self.images = [ SplitImage2(image) for image in image_list ]
for image in self.images:
if 'anchors' in image.image_dictionary:
for anchor in image.image_dictionary.anchors:
if 'tag' in anchor and anchor['tag'] is not None:
self.tags[anchor['tag']] = image
continue
[]
[]
def __contains__(self, tagname):
return tagname in self.tags
def tag_rect(self, tagname):
if tagname not in self.tags:
raise ValueError('tag %s not in this MultiImage' % tagname)
return self.drawrects[self.tags[tagname]]
def make_bitmap(self, width, height, mask_color = wx.BLACK):
bitmap = wx.EmptyBitmap(width, height)
if not hasattr(self, 'temp_dc'):
self.temp_dc = wx.MemoryDC()
self.temp_dc.SelectObject(bitmap)
self.draw(self.temp_dc, wx.Rect(0, 0, width, height))
self.temp_dc.SelectObject(wx.NullBitmap)
bitmap.SetMask(wx.Mask(bitmap, mask_color))
return bitmap
def draw(self, dc, rect):
self.drawrects = { }
_[1]
self.region = wx.Region(0, 0, 0, 0)
one = False
for image in self.images:
drect = wx.Rect(*self.drawrects[image])
drect.Offset((rect.x, rect.y))
if dc:
image.draw(dc, drect)
self.region.UnionRegion(image.region)
continue
[]
def compute_rect(self, image, dcrect):
myanchors = image.get_anchors_to()
numanchors = len(myanchors)
if image.image_dictionary.style != 'static':
if numanchors == 1:
anchorfrom = to_storage(myanchors[0])
tag = anchorfrom.to
imageto = self.tags[tag]
anchorto = [](_[1][0])
rectto1 = self.drawrects[imageto]
rectto2 = (0, 0, dcrect.width, dcrect.height)
positionto1 = compute_anchor_position(anchorto, rectto1[2:], rectto1[:2])
positionto2 = compute_anchor_position(get_SI2_anchor(image), rectto2[2:], rectto2[:2])
positionfrom1 = compute_anchor_position(anchorfrom, [
image.imgw,
image.imgh], [
0,
0])
positionfrom2 = (0, 0)
diffxto = abs(positionto1[0] - positionto2[0])
diffyto = abs(positionto1[1] - positionto2[1])
diffxlocal = abs(positionfrom1[0] - positionfrom2[0])
diffylocal = abs(positionfrom1[1] - positionfrom2[1])
increasex = diffxto - diffxlocal
increasey = diffyto - diffylocal
newsizew = image.imgw + increasex
newsizeh = image.imgh + increasey
newlocalanchorposition = positionto2
positiontodrawat = (positionfrom2[0] + newlocalanchorposition[0], positionfrom2[1] + newlocalanchorposition[1])
self.drawrects[image] = (positiontodrawat[0], positiontodrawat[1], newsizew, newsizeh)
return None
elif numanchors == 2:
(anchorfrom1, anchorfrom2) = myanchors
tag1 = anchorfrom1['to']
tag2 = anchorfrom2['to']
imageto1 = self.tags[tag1]
imageto2 = self.tags[tag2]
anchorto1 = _[2]
anchorto2 = _[3]
rectto1 = self.drawrects[imageto1]
rectto2 = self.drawrects[imageto2]
positionto1 = compute_anchor_position(anchorto1, rectto1[2:], rectto1[:2])
positionto2 = compute_anchor_position(anchorto2, rectto2[2:], rectto2[:2])
positionfrom1 = compute_anchor_position(anchorfrom1, [
image.imgw,
image.imgh], [
0,
0])
positionfrom2 = compute_anchor_position(anchorfrom2, [
image.imgw,
image.imgh], [
0,
0])
diffxto = abs(positionto1[0] - positionto2[0])
diffyto = abs(positionto1[1] - positionto2[1])
diffxlocal = abs(positionfrom1[0] - positionfrom2[0])
diffylocal = abs(positionfrom1[1] - positionfrom2[1])
increasex = diffxto - diffxlocal
increasey = diffyto - diffylocal
newsizew = image.imgw + increasex
newsizeh = image.imgh + increasey
newlocalanchorposition = compute_anchor_position(anchorfrom1, newsizew, newsizeh, [
0,
0])
positiontodrawat = (positionto1[0] - newlocalanchorposition[0], positionto1[1] - newlocalanchorposition[1])
self.drawrects[image] = (positiontodrawat[0], positiontodrawat[1], newsizew, newsizeh)
return None
else:
raise AssertionError('invalid skin, wrong number (%d) of anchors for image of type %s!' % (numanchors, image.image_dictionary['style']))
elif numanchors == 0:
positiontodrawat = compute_anchor_position(get_SI2_anchor(image), (dcrect.width, dcrect.height), [
0,
0])
self.drawrects[image] = (positiontodrawat[0], positiontodrawat[1], image.imgw, image.imgh)
return None
elif numanchors == 1:
anchorfrom = image.get_anchors_to()[0]
tag = anchorfrom['to']
imageto = self.tags[tag]
anchorto = _[4]
rectto = self.drawrects[imageto]
positionto = compute_anchor_position(anchorto, rectto[2:], rectto[:2])
positionfrom = compute_anchor_position(anchorfrom, [
image.imgw,
image.imgh], [
0,
0])
positiontodrawat = (positionto[0] - positionfrom[0], positionto[1] - positionfrom[1])
self.drawrects[image] = (positiontodrawat[0], positiontodrawat[1], image.imgw, image.imgh)
return None
else:
raise AssertionError('invalid skin, wrong number (%d) of anchors for image of type %s!' % (numanchors, image.image_dictionary['style']))
def compute_anchor_position(anchor, size, offset):
if 'halign' in anchor:
halign = anchor.halign
else:
halign = 'left'
if 'valign' in anchor:
valign = anchor.valign
else:
valign = 'top'
if 'offset' in anchor:
off = anchor.offset
else:
off = [
0,
0]
if isinstance(off[0], int):
myoffsetx = off[0]
else:
myoffsetx = int(str(off[0])[:-1]) * size[0] / 100
if isinstance(off[1], int):
myoffsety = off[1]
else:
myoffsety = int(str(off[1])[:-1]) * size[1] / 100
off = [
myoffsetx,
myoffsety]
tup = (offset[0], offset[1], size[0], size[1])
if halign == 'left':
x = 0
elif halign == 'right':
x = tup[2]
else:
x = tup[2] / 2
x = x + tup[0] + off[0]
if valign == 'top':
y = 0
elif valign == 'bottom':
y = tup[3]
else:
y = tup[3] / 2
y = y + tup[1] + off[1]
return (x, y)
def get_SI2_anchor(image):
retval = to_storage({ })
if hasattr(image.image_dictionary, 'offset'):
retval['offset'] = image.image_dictionary.offset
if hasattr(image.image_dictionary, 'valign'):
retval['valign'] = image.image_dictionary.valign
if hasattr(image.image_dictionary, 'halign'):
retval['halign'] = image.image_dictionary.halign
return retval
def main(images):
temp_dc = wx.MemoryDC()
temp_dc.SelectObject(destbitmap)
mimg = MultiImage(images)
drawrect = wx.Rect(10, 10, 220, 440)
mimg.draw(temp_dc, drawrect)
temp_dc.SelectObject(wx.NullBitmap)
if __name__ == '__main__':
import util
from skins import images as imgmngr
from skins import skins
app = wx.PySimpleApp()
skins.res_path = '../../res/'
destbitmap = imgmngr.get('skins/default/blue-flower.jpg')
f = file('../../res/skins/skinExample')
images = to_storage(syck.load(f)).Images
f.close()
util.profile(main, images)
destbitmap.SaveFile('C:/workspace/Digsby/res/skins/default/output.png', wx.BITMAP_TYPE_PNG)